#include "SDL2/SDL.h"

//直接播放bmp图片
//1:35:00

int main(int argc, char **argv) {

    SDL_Init(SDL_INIT_VIDEO);

    const char * fileName = argv[1];

    SDL_Window *window = SDL_CreateWindow("showBmp", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
    if (window == NULL) {
        SDL_Log("SDL_CreateWindow failed:%s\n", SDL_GetError());
        return -1;
    }

    SDL_Surface *windowSurface = SDL_GetWindowSurface(window);
    if (windowSurface == NULL) {
        SDL_Log("SDL_GetWindowSurface failed:%s\n", SDL_GetError());
        goto end;
    }
    
    SDL_Surface *bmpSurface = SDL_LoadBMP(fileName);
    if (bmpSurface == NULL) {
        SDL_Log("SDL_LoadBMP file %s failed:%s\n", fileName, SDL_GetError());
        goto end;
    }

    SDL_BlitSurface(bmpSurface, NULL, windowSurface, NULL);
    SDL_UpdateWindowSurface(window);

    while (1) {
        SDL_Event event;
        SDL_WaitEvent(&event);
//        SDL_PollEvent(&event);
        if (event.type == SDL_Quit) {
            break;
        }
        SDL_Log("event.type: %d\n", event.type);
    }


    end:
    if (bmpSurface) {
        SDL_FreeSurface(bmpSurface);
    }

//    SDL_Delay(5 * 1000);
    SDL_DestroyWindow(window);
    SDL_Quit();

    return 0;
}